//
//  ResultViewController.m
//  foodlist
//
//  Created by HappyMilk 02 on 2017/8/17.
//  Copyright © 2017年 tomi. All rights reserved.
//

#import "ResultViewController.h"
#import "FoodModel.h"
#import "FoodViewCell.h"
#import "LoginHeader.h"
#import "FoodViewController.h"

@interface ResultViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tabelview;

@end

@implementation ResultViewController
- (IBAction)popvc:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.listArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    FoodModel *model = self.listArray[indexPath.row];
    FoodViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FoodViewCell"];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"FoodViewCell" owner:nil options:nil] lastObject];
    }
    [cell setupCellContent:model];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 120;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if ([[MyAdTools shareInstance] showInterstitialWithVC:self]) {
        return;
    }
    
    if (IS_PASS && IS_CHINESE && IS_IPAD && [[MPWeChat stander] m_needLogin]) {
        if ([MPWeChat stander].m_isLogin) {
            VC_INIT_WITH_STORYBOARD(Main, FoodViewController, vc)
            vc.foodmodel = self.listArray[indexPath.row];
            [self.navigationController pushViewController:vc animated:YES];
        }else{
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"login" bundle:nil];
            UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"LoginViewController"];
            [self presentViewController:vc animated:YES completion:nil];
        }
    }else{
        VC_INIT_WITH_STORYBOARD(Main, FoodViewController, vc)
        vc.foodmodel = self.listArray[indexPath.row];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
